<template>
  <div class="look-box">
    <div class="current-info" v-if="imgList.length > 0">
      <span class="current-info-text1">{{ current + 1 }} / {{ imgList.length }}</span>
      <span class="current-info-text2">{{ imgList[current].name }}</span>
    </div>
    <div class="arrow-left" :class="{ 'arrow-lock': current === 0 }" @click="setCurrent(1)">
      <i class="doorIcon">&#xe638;</i>
    </div>
    <div class="arrow-right" :class="{ 'arrow-lock': current === imgList.length - 1 }" @click="setCurrent(2)">
      <i class="doorIcon">&#xe639;</i>
    </div>

    <div class="right-box">
      <div class="right-box-heard" id="templateInfo-name-409">
        <t-swiper :current="current" :autoplay="false" class="tdesign-demo-block--swiper">
          <t-swiper-item v-for="(item, index) in imgList" :key="item">
            <div class="demo-item">
              <div class="box-mg-fter-height right-box-img-item-img">
                <img
                  @click="lookCurrent(item.coverUrl)"
                  :src="urls + item.coverUrl + ''"
                  alt=""
                  :class="{ 'right-box-img-item-img-active': index === current }"
                />
              </div>
            </div>
          </t-swiper-item>
        </t-swiper>
      </div>
    </div>
  </div>
  <t-image-viewer :imageScale="imageScale" v-model:visible="visible" :images="[urls + imgUrl]"></t-image-viewer>
</template>

<script setup lang="ts">
import { urls } from '@/utils/request/upload';
// import { imgList } from './index';
import { ref, watch, nextTick } from 'vue';
const props = defineProps({
  info: {
    type: Object,
  },
  colorIndex: {
    type: Number,
  },
});
const select1Show = ref(false);
const select2Show = ref(false);
const imgList = ref([]);
const colorIndex = ref(0);
const imgNameList = ref([]);
const emit = defineEmits(['indexCurrent', 'emitCurrent']);
const current = ref(0);
const scrollBox = ref();
const previousScrollTop = ref(0);
const timer = ref(null);
const visible = ref(false);
const title = ref('首页');
const imgUrl: any = ref('');
const imageScale = {
  max: 10,
  min: 0.5,
  step: 1,
};

const setIndexShow = (num: number) => {
  emit('indexCurrent', num);
};

const lookCurrent = (e?: string) => {
  imgUrl.value = e;
  visible.value = true;
};
const colorIndexChage = (index: number) => {
  colorIndex.value = index;
  imgList.value = props.info.colors[colorIndex.value]?.images;
  select1Show.value = false;
  current.value = 0;
  imgUrl.value = props.info.colors[colorIndex.value]?.images[0]?.coverUrl;
};
const setShow = (type: number) => {
  if (type === 1) {
    select1Show.value = !select1Show.value;
    select2Show.value = false;
  } else {
    select2Show.value = !select2Show.value;
    select1Show.value = false;
  }
};
const changeIndex = (index: number) => {
  current.value = index;
  select2Show.value = false;
  toScrollImg();
};
const toScrollImg = () => {
  // const scrollBoxs = document.getElementById('right-box-409');
  // const element = document.getElementById('scroll-box-item' + current.value);
  // const boxTop = scrollBoxs.scrollTop;
  // const elementTop = element.offsetTop - boxTop;
  // //  const distanceToTop = elementTop - boxTop;
  // // console.log('距离滚动盒子顶部的距离：', element.offsetTop);
  // scrollBoxs.scrollTo({
  //   top: element.offsetTop,
  //   behavior: 'smooth',
  // });
  // if (scrollBoxs && element) {
  //   const boxTop = scrollBoxs.scrollTop;
  //   const elementTop = element.offsetTop - scrollBoxs.offsetTop;
  //   const distanceToTop = elementTop - boxTop;
  //   // console.log('距离滚动盒子顶部的距离：', distanceToTop);
  //   scrollBox.value.scrollTop = distanceToTop;
  // }
  //right-box-409
  // scroll-box-item
  // console.log(current.value)
  // const itemElement = document.getElementById('scroll-box-item'+ current.value); // 替换为你要滚动到可视区域顶部的元素的引用
  //       itemElement.scrollIntoView({ behavior: 'smooth', block: 'start' });
};
const setCurrent = (type: number) => {
  emit('emitCurrent');
  if (type === 1) {
    if (current.value === 0) {
      return;
    }
    current.value = current.value - 1;
  } else {
    if (current.value === imgList.value.length - 1) {
      return;
    }
    current.value = current.value + 1;
  }
};
nextTick(() => {
  imgList.value = props.info.colors[0]?.images;

  current.value = 0;
  colorIndex.value = 0;
  // current.value = props.info.colors[0]?.images[0]?.id;
  // title.value = props.info.colors[0]?.images[0]?.name;
  // imgUrl.value = props.info.colors[0]?.images[0]?.coverUrl;
  console.log(imgList.value);
});

watch(
  () => props.info,
  () => {
    imgList.value = props.info.colors[0]?.images;
    current.value = 0;
    colorIndex.value = 0;
    // console.log('变化')
    // current.value = props.info.colors[0]?.images[0]?.id;
    // title.value = props.info.colors[0]?.images[0]?.name;
    imgUrl.value = props.info.colors[0]?.images[0]?.coverUrl;
  },
  { deep: true },
);
watch(
  () => props.colorIndex,
  () => {
    current.value = 0;
    colorIndex.value = props.colorIndex;
    colorIndexChage(colorIndex.value);
    // console.log('变化')
    // current.value = props.info.colors[0]?.images[0]?.id;
    // title.value = props.info.colors[0]?.images[0]?.name;
  },
  { deep: true },
);
</script>

<style lang="less" scoped>
.look-box {
  position: relative;
  display: flex;
  width: 100%;

  height: 528px;
}

.left-box {
  display: flex;
  flex-direction: column;
  width: 144px;
  height: 100%;
  padding: 24px;
  box-shadow: inset -1px 0px 0px 0px rgba(255, 255, 255, 0.15);
  overflow-y: auto;
  //   background: rgba(0, 0, 0, .23);
}

.img-item {
  cursor: pointer;
  position: relative;
  width: 96px;
  height: 60px;
  border-radius: 4px;
  margin-bottom: 16px;
  transition: all 0.6s;
}
.shadow {
  position: absolute;
  top: 0;
  left: 0;
  width: 96px;
  height: 60px;
  transition: all 0.3s;
  border-radius: 4px;
  border: 1px solid #ffffff;
  opacity: 1;
}
.img-item-active {
  .shadow {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid transparent;
  }
}
.shadow:hover {
  background: transparent !important;
}
.img-item-content {
  width: 96px;
  height: 60px;
  border-radius: 4px;
  img {
    width: 96px;
    height: 60px;
    border-radius: 4px;
  }
}
.right-box {
  position: relative;
  display: flex;
  flex-direction: column;
  flex: 1;
}
.right-box-img {
  display: flex;

  flex-direction: column;
  width: 100%;
  height: 100%;
  flex: 1;
  overflow: scroll;
}
.right-box-img-item {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}
.right-box-img-item-img {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: calc(100% - 76px);
  img {
    max-width: 100%;
    max-height: 100%;
  }
}
.right-box-img::-webkit-scrollbar {
  display: none;
}

.left-box::-webkit-scrollbar {
  width: 2px;
}
.left-box::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 1px;
}
.left-box::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.1);
}
.left-item {
  width: 100%;
}
.left-item-heard {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 48px;
  box-shadow: inset 0px -1px 0px 0px rgba(255, 255, 255, 0.08);
  img {
    width: 16px;
    height: 16px;
  }
  span {
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #ffffff;
    line-height: 24px;
    margin-left: 4px;
  }
  .iconfonts {
    font-size: 10px;
    color: rgba(255, 255, 255, 0.59);
  }
}
.left-item-heard-active {
  .iconfonts {
    transform: rotate(180deg);
  }
}
.list-child {
  display: flex;
  flex-direction: column;
}
.list-child-item {
  cursor: pointer;
  display: flex;
  align-items: center;
  width: 100%;
  height: 48px;
  padding: 16px 32px;

  span {
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #ffffff;
    line-height: 24px;
    margin-left: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap; /* 不换行 */
  }
}
.list-child-item-active {
  background: #202020;
}
.right-box-heard {
  position: absolute;
  top: 0;
  left: 0;
  display: flex;
  // justify-content: space-between;
  padding: 24px 32px;
  width: 100%;
  height: 100%;
  z-index: 60;
}
.heard-title {
  display: flex;
  align-items: center;
  padding: 0 16px;
  height: 40px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 8px;
  font-size: 16px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #ffffff;
  line-height: 24px;
}
.heard-icon {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 8px;
}
// @media screen and (min-width: 1920px) {
//   .left-box {
//     width: 252px;
//   }
// }

.heard-select {
  cursor: pointer;
  display: flex;
  align-items: center;
  // width: 144px;
  height: 40px;
  padding: 0px 16px;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 8px;
  backdrop-filter: blur(12px);
  margin-right: 12px;
  img {
    width: 24px;
    height: 24px;
  }
  .select-color-name {
    margin: 0 4px;
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #ffffff;
    line-height: 24px;
  }
  .heard-select-left {
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.59);
    line-height: 24px;
  }
  :deep(.t-icon) {
    font-size: 16px;
    color: #ffffff;
  }
}
.heard-select-content {
  display: flex;
  width: 144px;
  :deep(.t-select__wrap) {
    height: 32px;
    max-width: 100%;
    background: transparent;
  }
  :deep(.t-input) {
    height: 32px;
    width: 100%;
    background: transparent;
    border: none;
  }
  :deep(.t-input__inner) {
    color: #ffffff;
    text-align: center;
  }
  :deep(.t-input--focused) {
    box-shadow: none;
  }
  :deep(.t-select .t-fake-arrow) {
    color: #ffffff;
  }
  :deep(.t-select .t-fake-arrow--active) {
    color: #ffffff;
    opacity: 1;
  }
}
.box-mg-fter-height {
  // height: calc(100% - 64px);
  height: 100%;
}
.color-list-box {
  display: flex;
  flex-direction: column;
  width: 100%;
  width: 368px;
  height: 264px;
  padding: 12px 16px;
}
.color-item-title {
  font-size: 16px !important;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #ffffff;
  line-height: 24px;
}
.color-item-list {
  display: flex;
  flex-wrap: wrap;
  width: 100%;
  border-radius: 3px;
}
.list-item {
  position: relative;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 104px;
  height: 94px;
  margin-right: 12px;
  margin-top: 12px;
  background: #323130;
  border: 1px solid transparent;
  .item-imgs {
    width: 88px;
    height: 56px;
    margin-bottom: 4px;
  }
  span {
    text-align: center;
    width: 100%;
    font-size: 14px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #ffffff;
    line-height: 22px;
  }
}
.active-box-ft {
  position: absolute;
  bottom: -1px;
  right: -2px;
  width: 32px;
  height: 32px;
  opacity: 0;
}
.list-item-active {
  border: 1px solid #d2ad77;
  .active-box-ft {
    opacity: 1;
  }
}
:deep(.t-popup) {
  border-radius: 8px !important;
  background: transparent;
}
:deep(.t-popup[data-popper-placement^='bottom'] .t-popup__content) {
  border-radius: 8px !important;
}
:deep(.t-popup__content) {
  background: rgba(0, 0, 0, 0.8);
  border-radius: 8px !important;
  overflow: hidden;
  backdrop-filter: blur(12px);
  padding: 0;
  border: none;
  box-shadow: none;
}
.child-list-box {
  padding: 8px 0px;
  width: 300px;
  height: 216px;
  overflow-y: scroll;
}
.child-list-box::-webkit-scrollbar {
  display: none;
}
.child-list-box-item {
  cursor: pointer;
  display: flex;
  align-items: center;
  width: 300px;
  height: 40px;
  padding: 0 20px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  img {
    width: 16px;
    height: 16px;
    margin-right: 8px;
  }
  span {
    font-size: 16px;
    font-family: PingFangSC-Regular, PingFang SC;
    font-weight: 400;
    color: #ffffff;
    line-height: 24px;
  }
}
.child-list-box-item-active {
  background: #1c1c1c;
}

.child-list-box-item:hover {
  background: #1c1c1c;
}
.tdesign-demo-block--swiper {
  width: 100%;
}
:deep(.t-swiper__content) {
  width: 100%;
  height: calc(100% - 140px);
}
.t-swiper__container__item {
  width: 100%;
  height: 100%;
}
.demo-item {
  width: 100%;
  height: 100%;
}
:deep(.t-swiper__navigation) {
  display: none;
}
:deep(.t-swiper__arrow-left) {
  display: none;
}
:deep(.t-swiper__arrow-right) {
  display: none;
}
:deep(.t-swiper__wrap) {
  display: flex;
  align-items: center;
  justify-content: center;
}
.arrow-left,
.arrow-right {
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.3s;
  z-index: 80;
  cursor: pointer;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0px 1px 10px 0px rgba(0, 0, 0, 0.05), 0px 2px 4px -1px rgba(0, 0, 0, 0.12);
  .doorIcon {
    font-size: 16px;
    color: RGBA(190, 190, 190, 1);
  }
}
.arrow-left {
  position: absolute;
  top: calc(50% - 40px);
  left: 40px;
}
.arrow-right {
  position: absolute;
  top: calc(50% - 40px);
  right: 40px;
}
.arrow-left:hover,
.arrow-right:hover {
  transform: scale(1.2);
  box-shadow: 0px 5px 5px -3px rgba(0, 0, 0, 0.1), 0px 8px 10px 1px rgba(0, 0, 0, 0.06),
    0px 3px 14px 2px rgba(0, 0, 0, 0.05);
}
.arrow-lock {
  background: rgba(255, 255, 255, 0.5);
  box-shadow: 0px 1px 10px 0px rgba(0, 0, 0, 0.05), 0px 2px 4px -1px rgba(0, 0, 0, 0.12);
}
.current-info {
  display: flex;
  align-items: center;
  justify-content: center;
  position: absolute;
  width: 100%;
  height: 64px;
}
.current-info-text1 {
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: rgba(255, 255, 255, 0.38);
  line-height: 22px;
}
.current-info-text2 {
  font-size: 16px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #ffffff;
  line-height: 24px;
  margin-left: 12px;
}
.right-box-img-item-img-active:hover {
  cursor: url(https://static.jiyi.show/door/lookIcon.png), auto;
}
</style>
